package org.csu.mypetstorems.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.csu.mypetstorems.entity.Order;
import org.csu.mypetstorems.entity.PageBean;
import org.csu.mypetstorems.mapper.OrderMapper;
import org.csu.mypetstorems.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("orderService")
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Boolean changeState(String status, String id) {
        return orderMapper.changeState(status, id) > 0;
    }

    @Override
    public PageBean<Order> getOrderListWithCondition(Integer pageNum, Integer pageSize, String orderId, String phone) {
        PageBean<Order> pageBean = new PageBean<>();
        PageHelper.startPage(pageNum, pageSize);
        List<Order> OrderList = orderMapper.getOrderListWithCondition(orderId, phone);
        Page<Order> page = (Page<Order>) OrderList;
        pageBean.setTotal(page.getTotal());
        pageBean.setList(page.getResult());
        return pageBean;
    }
}
